package com.itheima.arraylist;

import com.itheima.domain.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class Demo3ArrayList {
    /*
    键盘录入信息到集合
     */
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student s1 = getStudent();
        Student s2 = getStudent();
        Student s3 = getStudent();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu.getName()+"..."+stu.getAge());
        }
    }

    public static Student getStudent() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名");
        String name = sc.next();
        System.out.println("请输入年龄");
        int age = sc.nextInt();
        Student stu = new Student(name,age);
        return  stu;
    }
}
